<!-- 任务委托 - 项目专员 -->
<template>
  <view>
    <u--form
      labelPosition="top"
      :model="form"
      :rules="rules"
      ref="form"
      labelWidth="auto"
      :labelStyle="{
        fontSize: '14px',
        color: '#B2B2B2',
        lineHight: '20px',
      }"
    >
      <view class="basic-style">
        <view class="basic-title basic-border">基础信息</view>
        <u-form-item label="单据编号" prop="billNo" :borderBottom="false" required>
          <u--input disabled placeholder="请输入单据编号" v-model="form.billNo" border="surround"></u--input>
        </u-form-item>
        <u-form-item label="申请时间" prop="createTime" :borderBottom="false" required>
          <u--input
            v-model="form.createTime"
            disabled
            placeholder="请选择时间"
            border="surround"
            suffixIcon="calendar-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="申请人" prop="handlerId" :borderBottom="false" required>
          <h-select-person-input
            style="width: 100%"
            disabled
            v-model="form.handlerId"
            placeholder="请选择申请人"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="form.handlerId"
          ></h-select-person-input>
        </u-form-item>
        <u-form-item label="申请部门" prop="handlerDeptId" :borderBottom="false" required>
          <h-select-depart-input
            disabled
            v-model="form.handlerDeptId"
            :departName="form.handlerDeptIdText"
            placeholder="请选择部门"
            border="surround"
            style="width: 100%"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :title.sync="form.handlerDeptIdText"
          ></h-select-depart-input>
        </u-form-item>
      </view>
      <view class="basic-style">
        <view class="basic-title basic-border">项目信息</view>
        <u-form-item label="项目名称" prop="projectId" required>
          <h-select-project-input-popup
            :proDisabled="true"
            :projectStatus="'2'"
            ref="projectSelect"
            v-model="form.projectId"
            style="width: 100%"
            placeholder="请选择项目名称"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-select-project-input-popup>
          <!-- @change="handleProjectIdChange" -->
        </u-form-item>
        <u-form-item label="项目编号" prop="finalNo" :borderBottom="false">
          <u--input v-model="form.finalNo" disabled placeholder="请输入项目编号" border="surround"></u--input>
        </u-form-item>
        <u-form-item label="关联任务" prop="taskId" required :borderBottom="false">
          <h-select-task-file-input-popup
            :projectId="form.projectId"
            v-model="form.taskId"
            class="w-100"
            :label="'billNo'"
            :disabled="!form.projectId"
            :placeholder="form.projectId ? '请选择任务' : '请先选择项目'"
            searchPlaceholder="请输入生产团队"
            :isShowAsterisk="false"
            searchName="productTeamText"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            @realChange="handleTaskIdChange"
            :customParams="{
              changeStatus: '!changing',
              distributionType: '!waiting',
            }"
            @select="form.taskDescription = $event.data.taskDescription"
          ></h-select-task-file-input-popup>
        </u-form-item>
        <u-form-item label="业务名称" prop="categoryName" :borderBottom="false">
          <u--input v-model="form.categoryName" disabled placeholder="请输入业务名称" border="surround"></u--input>
        </u-form-item>
        <u-form-item label="项目负责人" prop="projectLeading" :borderBottom="false">
          <h-select-person-input
            style="width: 100%"
            disabled
            v-model="form.projectLeading"
            placeholder="请选择项目负责人"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="form.projectLeading"
          ></h-select-person-input>
        </u-form-item>
        <u-form-item label="生产团队" prop="productTeam" :borderBottom="false">
          <h-select-team-input
            style="width: 100%"
            disabled
            v-model="form.productTeam"
            objectField="form.productTeam"
            placeholder="请选择生产团队"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :tdlx="2"
          ></h-select-team-input>
        </u-form-item>
        <u-form-item label="实施部门" prop="executeDepart" :borderBottom="false">
          <h-select-depart-input
            v-model="form.executeDepart"
            :departName="form.executeDepartText"
            placeholder="请选择部门"
            disabled
            border="surround"
            style="width: 100%"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :title.sync="form.executeDepartText"
            @detail="onExecuteDepartInput"
          ></h-select-depart-input>
        </u-form-item>
        <u-form-item label="资质单位" prop="qualificationUnit" required>
          <h-select-company-input
            style="width: 100%"
            v-model="form.qualificationUnit"
            border="surround"
            placeholder="请选择资质单位"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="form.qualificationUnit"
          ></h-select-company-input>
        </u-form-item>
        <u-form-item label="签订单位" prop="signUnit" :borderBottom="false">
          <h-select-company-input
            disabled
            style="width: 100%"
            v-model="form.signUnit"
            border="surround"
            placeholder="请选择签订单位"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="form.signUnit"
          ></h-select-company-input>
        </u-form-item>
        <u-form-item label="项目所在地址" prop="areaCode" :borderBottom="false">
          <h-select-address-input
            disabled
            style="width: 100%"
            v-model="form.areaCode"
            placeholder="请选择项目地址"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-select-address-input>
        </u-form-item>
        <u-form-item label="项目详细地址" prop="projectAddress" :borderBottom="false">
          <u--input v-model="form.projectAddress" disabled placeholder="请输入项目详细地址"></u--input>
        </u-form-item>
 
        <u-form-item label="任务类型" prop="taskType" required>
          <h-select-input-tag
            class="w-100"
            disabled
            v-model="form.taskType"
            objectField="model.taskType"
            placeholder="请选择任务类型"
            border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
            dictName="task_type"
          ></h-select-input-tag>
        </u-form-item>
        <u-form-item label="任务最终成果报告名称(全称)" prop="projectResult" :borderBottom="false" required>
          <u--textarea v-model="form.projectResult" :maxlength="1000" count :confirm-type="null" placeholder="请输入任务最终成果报告名称(全称)"></u--textarea>
        </u-form-item>
        <u-form-item label="备注" prop="remark" :borderBottom="false">
          <u--textarea v-model="form.remark" :maxlength="200" count :confirm-type="null" placeholder="请输入备注"></u--textarea>
        </u-form-item>
   
        <u-form-item label="项目评审情况" prop="reviewResult" :borderBottom="false">
          <h-dict-select
            style="width: 100%"
            disabled
            v-model="form.reviewResult"
            placeholder="请选择项目评审情况"
            dictName="review_result"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-dict-select>
        </u-form-item>
        <u-form-item v-if="form.taskType === '1'" label="报告类型" prop="reportType" required>
          <h-select-input-tag
            class="w-100"
            v-model="form.reportType"
            objectField="form.reportType"
            placeholder="请选择报告类型"
            border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
            dictName="report_audit_report_type"
          ></h-select-input-tag>
        </u-form-item>
        <u-form-item label="费用所属团队" prop="feeTeamId">
          <h-select-team-input
            style="width: 100%"
            v-model="form.feeTeamId"
            disabled
            objectField="form.feeTeamId"
            placeholder="请选择费用所属团队"
            border="surround"
            :tdlx="3"
          />
        </u-form-item>
      </view>
      <view class="basic-style">
        <view class="basic-title basic-border">一审工程师</view>
        <!-- <view class="basic-title basic-border pt-1">新增分配任务信息</view> -->
        <!-- <view class="space-y-1 py-1">
          <u-button size="small" type="primary" @click="handleAddMember">新增</u-button>
        </view>
        <u-collapse v-if="formData && formData.length">
          <u-collapse-item title="二审会审工程师" v-for="(item, index) in formData" :key="index">
            <FormInfo :item="item" :index="index" @edit="handleEditForm" @remove="handleRemoveForm" @copy="handleCopyForm" />
          </u-collapse-item>
        </u-collapse>
        <u-popup mode="bottom" :show="showFormModal">
          <TaskForm
            ref="dataForm"
            :estimatedContractAmount="form.estimatedContractAmount"
            :separateContractAmount="form.separateContractAmount"
            :index="index"
            @submit="handleFormSubmit"
            @close="closeFormModal"
            :model="form"
          />
        </u-popup> -->
        <ErpFirstInstanceEngineerList :firstInstanceEngineer="true" :twoProjectSpecialist="true" ref="firstInstanceEngineerList" />
        <!-- <u-form-item label="姓名" prop="applyAuthPerson" required>
						<h-select-person-input-popup
						  style="width: 100%"
						  v-model="firstAuditEngineers.empId"
              @back="changeVal"
						  placeholder="请选择人员"
						  border="surround"
						  suffixIcon="arrow-down-fill"
						  :suffixIconStyle="{ color: '#B2B2B2' }"
						  objectField="model.applyAuthPerson"
						></h-select-person-input-popup>
				</u-form-item>
        <u-form-item label="所属团队" prop="teamId" required>
          <h-select-team-input
					  @input="changeBusinessCompany"
						style="width: 100%;"
						v-model="firstAuditEngineers.teamId"
						objectField="firstAuditEngineers.teamId"
						placeholder="请选择团队"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
						:tdlx="1"
					></h-select-team-input>
        </u-form-item>
        <u-form-item label="预计审核费" prop="finalNo" :borderBottom="false">
          <u--input v-model="firstAuditEngineers.expectedAuditFee" placeholder="请输入预计审核费" border="surround"></u--input>
        </u-form-item>
        <u-form-item label="扣除比例" prop="finalNo" :borderBottom="false">
            <h-dict-select
            style="width: 100%" 
            v-model="firstAuditEngineers.deductionRatio" 
            placeholder="请选择" 
            dictName="deduction_ratio" 
            suffixIcon="arrow-down-fill" 
            :suffixIconStyle="{color: '#B2B2B2'}"
          ></h-dict-select>
        </u-form-item>
        <u-form-item label="实际审核费" prop="finalNo" :borderBottom="false">
          <u--input v-model="firstAuditEngineers.actualAuditFee" disabled placeholder="请输入实际审核费" border="surround"></u--input>
        </u-form-item>
            <view>
            <view class="basic-title basic-border">一审文件结果</view>
            <view class="py-1 space-y-1" style="width: 100%">
              <view style="color: red">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
              <h-upload-file v-model="form.file" :isIcon="false"></h-upload-file>
              <file-list v-if="form.file" v-model="form.file" :isDelete="true"></file-list>
            </view>
          </view>
          <u-form-item label="备注" prop="remark" :borderBottom="false">
          <u--textarea v-model="form.remark" :maxlength="200" placeholder="请输入备注"></u--textarea>
        </u-form-item> -->
      </view>
      <view class="basic-style">
        <view class="basic-title basic-border">二审主持工程师</view>
         <ErpSecondInstancePresidingEngineerForm :firstInstanceEngineer="true" :oneProjectSpecialist="true" :twoProjectSpecialist="true" ref="SecondInstancePresidingEngineerForm" />
      </view>
      <view class="basic-style">
        <view class="basic-title basic-border">二审会审工程师</view>
         <!-- <ErpSecondInstanceReviewEngineerForm /> -->
            <!-- <view class="basic-title basic-border pt-1">新增分配任务信息</view> -->
        <view class="space-y-1 py-1">
          <u-button size="small" :disabled="true"  type="primary" @click="handleAddMember">新增</u-button>
        </view>
        <u-collapse v-if="secondAuditReviewEngineers && secondAuditReviewEngineers.length">
          <u-collapse-item title="二审会审工程师" v-for="(item, index) in secondAuditReviewEngineers" :key="index">
            <FirstInstanceEngineerForm :item="item" :index="index" @edit="handleEditForm" @remove="handleRemoveForm" @copy="handleCopyForm" />
          </u-collapse-item>
        </u-collapse>
        <u-popup mode="bottom" :show="showFormModal">
          <FirstInstanceEngineerModal
            ref="dataForm"
            :estimatedContractAmount="form.estimatedContractAmount"
            :separateContractAmount="form.separateContractAmount"
            :index="index"
            @submit="handleFormSubmit"
            @close="closeFormModal"
            :model="form"
          />
        </u-popup>
      </view>
      <view class="basic-style" v-if="form.taskType === '1'">
        <view class="basic-title basic-border">三审工程师</view>
        <view class="space-y-1 py-1">
          <u-button size="small" :disabled="true" type="primary" @click="handleAddMember">新增</u-button>
        </view>
        <u-collapse v-if="formData && formData.length">
          <u-collapse-item title="三审工程师" v-for="(item, index) in formData" :key="index">
            <FirstInstanceEngineerForm :item="item" :index="index" @edit="handleEditForm" @remove="handleRemoveForm" @copy="handleCopyForm" />
          </u-collapse-item>
        </u-collapse>
        <u-popup mode="bottom" :show="showFormModal">
          <FirstInstanceEngineerModal
            ref="dataForm"
            :estimatedContractAmount="form.estimatedContractAmount"
            :separateContractAmount="form.separateContractAmount"
            :index="index"
            @submit="handleFormSubmit"
            @close="closeFormModal"
            :model="form"
          />
        </u-popup>
      </view>
      <view class="basic-style" v-if="form.taskType === '1'">
        <view class="basic-title basic-border">专审人员</view>
        <!-- <ErpSecondInstanceReviewEngineerForm /> -->
        <!-- <view class="basic-title basic-border">二审会审工程师</view> -->
            <!-- <view class="basic-title basic-border pt-1">新增分配任务信息</view> -->
       <view class="space-y-1 py-1">
          <u-button size="small" :disabled="true" type="primary" @click="handleAddMember">新增</u-button>
        </view>
        <u-collapse v-if="formData && formData.length">
          <u-collapse-item title="专审人员" v-for="(item, index) in formData" :key="index">
            <FirstInstanceEngineerForm :item="item" :index="index" @edit="handleEditForm" @remove="handleRemoveForm" @copy="handleCopyForm" />
          </u-collapse-item>
        </u-collapse>
        <u-popup mode="bottom" :show="showFormModal">
          <FirstInstanceEngineerModal
            ref="dataForm"
            :estimatedContractAmount="form.estimatedContractAmount"
            :separateContractAmount="form.separateContractAmount"
            :index="index"
            @submit="handleFormSubmit"
            @close="closeFormModal"
            :model="form"
          />
        </u-popup> 

      </view>
      <view class="basic-style">
        <view class="basic-title basic-border">附件信息</view>
        <view class="py-1 space-y-1" style="width: 100%">
          <view style="color: red">提示：请等待附件上传完成，再点击保存，否则附件无法保存成功！</view>
          <h-upload-file v-model="form.file" :isIcon="false"></h-upload-file>
          <file-list v-if="form.file" v-model="form.file" :isDelete="true"></file-list>
        </view>
      </view>

      <view class="space-x-1 px-1 btn_position">
        <u-button :disabled="isSubmit" type="primary" :plain="true" text="保存" @click="onDraft"></u-button>
        <u-button :disabled="isSubmit" type="primary" text="保存并提交" @click="onSubmit"></u-button>
      </view>
      <view style="height: 100rpx"></view>
      <u-toast ref="uToast"></u-toast>
      <ProcessNodeConfiguration ref="processConfig" isAfterStart="1" isCheck="1" @ok="onOk"></ProcessNodeConfiguration>
    </u--form>
  </view>
</template>

<script>
import moment from 'moment'
import fileList from '@/pages/synergy/components/fileList.vue'
import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'
import { add, edit, info, getBillNo } from '@/api/project/erpReportAudit.js'
import { mapState } from 'vuex'
// import FormInfo from '@/pages/project/components/TaskFormInfo.vue'
// import TaskForm from '@/pages/project/components/TaskForm.vue'
import FirstInstanceEngineerModal from '@/pages/project/components/FirstInstanceEngineerModal.vue'

import FirstInstanceEngineerForm from '@/pages/project/components/FirstInstanceEngineerForm.vue' 

import ErpFirstInstanceEngineerList from '@/pages/project/components/reference/ErpFirstInstanceEngineerList.vue'
import ErpSecondInstancePresidingEngineerForm from '@/pages/project/components/reference/ErpSecondInstancePresidingEngineerForm.vue'
import ErpSecondInstanceReviewEngineerForm from '@/pages/project/components/reference/ErpSecondInstanceReviewEngineerForm.vue'
import ErpThirdReviewEngineerForm from '@/pages/project/components/reference/ErpThirdReviewEngineerForm.vue'
import ErpSpecializedAuditorsForm from '@/pages/project/components/reference/ErpSpecializedAuditorsForm.vue'
// import defaultList from '@/pages/synergy/components/defaultList.vue'
import ProcessNodeConfiguration from '@/components/ProcessNodeConfiguration/ProcessNodeConfiguration.vue' // 流程节点配置人员选择弹窗
import http from '@/utils/request'
export default {
  components: {
    fileList,
    ProcessNodeConfiguration,
    ErpFirstInstanceEngineerList,
    FirstInstanceEngineerForm,
    FirstInstanceEngineerModal,
    // FormInfo,
    // TaskForm,
    ErpSecondInstancePresidingEngineerForm,
    ErpSecondInstanceReviewEngineerForm,
    ErpSpecializedAuditorsForm,
    ErpThirdReviewEngineerForm
    // defaultList,
  },
  data() {
    return {
      projectIdBack: null,
      hideFlag: '0',
      index:null,
      showFormModal:false,
      applyAuthPerson:'',
      // 一审工程师
      firstAuditEngineers:{
        deptId:'',
        empId:'',
        teamId:'',
        deductionRatio:''
      },
      formData:[],
      secondAuditReviewEngineers:[],
      firstInstanceEngineerList:null,
      SecondInstancePresidingEngineerForm:null,
      form: {
        bpmBizTitle: '',
        reportType:'',
        billNo: '',
        handlerId: '',
        handlerDeptId: '',
        createTime: '',
        projectId: '',
        finalNo: '',
        taskId: '',
        billType:'create',
        categoryName: '',
        projectLeading: '',
        productTeam: '',
        executeDepart: '',
        qualificationUnit: '',
        signUnit: '',
        areaCode: '',
        projectAddress: '',
        projectResult: '',
        remark: '',
        engineerSecondReview: '',
        engineerThirdReview: '',
        reviewResult: '',
        secondReviewFee: '',
        secondReviewProcess: '',
        thirdReviewFee: '',
        thirdReviewProcess: '',
        feeTeamId: '',
        // feeTeamId_dictText: '',
        industryCategory: '',
        industryCoefficient: '',
        approvalLevel: '',
        approvalCoefficient: '',
        complexity: '',
        complexCoefficient: '',
        file: '',
        
      },
      rules: {
        billNo: [{ required: true, message: '请输入单据编号!', trigger: ['blur', 'change'] }],
        handlerDeptId: [{ required: true, message: '请选择申请部门!', trigger: ['blur', 'change'] }],
        handlerId: [{ required: true, message: '请选择申请人!', trigger: ['blur', 'change'] }],
        createTime: [{ required: true, message: '请选择申请时间!', trigger: ['blur', 'change'] }],

        projectId: [{ required: true, message: '请选择项目名称!', trigger: ['blur', 'change'] }],
        taskId: [{ required: true, message: '请选择关联任务!', trigger: ['blur', 'change'] }],
        qualificationUnit: [{ required: true, message: '请选择资质单位!', trigger: ['blur', 'change'] }],
        projectResult: [{ required: true, message: '请输入项目成果!', trigger: ['blur', 'change'] }],
        reportType: [{ required: true, message: '请选择报告类型!', trigger: ['blur', 'change'] }],
      },
      initDictOptions,
      dictOptions: {},
      isSubmit: false,
      basicForm: {},
      nodeObj: {},
      tabvalue: '',
      id: '', // 详情id值
      model: {},
      //代码生成后需手动设置流程编码
      flowCode: 'onl_erp_report_audit',
      formUrl: '/erp/omc/reportaudit/modules/ErpReportAuditForm',
      formUrlMobile: '/pages/synergy/ErpReportAuditForm',
      beanName: 'ErpReportAuditFlow',
			urlStartProcess: '/api/erpmng/act/process/activiti/startMutilProcessCanBack'
    }
  },
  onLoad({ id }) {
    this.id = id || ''
  },
  onReady() {
    this.$refs.projectSelect.$on('change', (event) => {
      this.handleProjectIdChange(event)
    })
  },
  onUnload() {
    this.$off('change')
  },
  created() {
    if (this.id) {
      this.loadData(this.id)
    } else {
      this.initForm()
      this.initBillNo()
    }
    this.initDictConfig()
  },
  computed: {
    ...mapState(['userInfo']),
  },
  methods: {
    onExecuteDepartInput(item){

    },
    handleAddMember() {
      this.index = null
      this.showFormModal = true
			this.basicForm = {}
			this.openFormModal()
    },
    
    openFormModal() {
      this.$nextTick(() => {
				this.$refs.dataForm.basicForm = this.basicForm
			})
    },
    closeFormModalC() {
			this.$refs.dataFormC.reset()
			this.basicFormC = {}
			this.formDataCIndex = null
			this.showFormModalC = false
		},

    closeFormModal(){
      this.$refs.dataForm.reset()
      this.basicForm = {}
      this.index = null
			this.showFormModal = false
    },
     

    handleRemoveForm(data){
      this.secondAuditReviewEngineers = this.secondAuditReviewEngineers.filter((i) => i !== data)
    },

    handleCopyForm([item, index]){

    },

    handleFormSubmit([data, index]) {
      this.showFormModal = false

      // this.showFormModal = false
      if (typeof index === 'number') {
        this.$set(this.secondAuditReviewEngineers, index, { ...data })
        // 当是编辑的时候，查看需分配款项信息中的数据是否有绑定此任务，如果绑定则替换成新数据
        if (this.receivablePaymentList && this.receivablePaymentList.length > 0) {
          this.receivablePaymentList.forEach((item, index) => {
            if (item && item.planTaskVoList && item.planTaskVoList.length > 0) {
              item.planTaskVoList.forEach((item1, ind) => {
                if (item1.taskId == data.id) {
                  let obj = {
                    ...item1,
                    categoryName: data.categoryName,
                    taskDesc: data.taskDescription,
                    productTeam: data.productTeam,
                    productCompanyId: data.productCompanyId,
                    productTeamName: data.productTeam_dictText
                  }
                  // data.planId = item.planId
                  this.receivablePaymentList[index].planTaskVoList.splice(ind, 1, obj);
                }
              })
            }
          })
          this.receivablePaymentList.map((value, index) => {
            this.receivablePaymentList[index].taskId_dictText = '' // 首先款项关联任务字段默认为空
            // 遍历planTaskList数组赋值给taskId_dictText
            this.receivablePaymentList[index].taskId_dictText = value.planTaskVoList && value.planTaskVoList.length ? (value.planTaskVoList.map((obj) => { return obj.categoryName }).join(',')) : '';
          })
        }
      } else {
        this.secondAuditReviewEngineers.push(data)
      }
   
    },

    handleEditForm([item, index]) {
      this.basicForm = { ...item }
      this.index = index
      this.showFormModal = true
			this.openFormModal()
    },

    changeVal(val){
      console.log(val,'val-----');
      
    },

    // 提交流程成功
    onOk() {
      this.$refs.uToast.show({
        message: '提交成功',
        type: 'success',
        complete() {
          if (getCurrentPages().length > 1) {
            uni.navigateBack()
          } else {
            uni.reLaunch({
              url: '/pages/home/home',
            })
          }
        },
      })
    },
    fillOrHide(task, isEdit) {
			if (task && task.taskType && (task.taskType == 1 || task.taskType == 4)) {
				// 行业类别
				this.$set(this.form, 'industryCategory', task.industryCategory) // 行业类别
				// 行业系数
				this.$set(this.form, 'industryCoefficient', task.industryCoefficient) // 行业系数
				// 审批类别(环评)
				this.$set(this.form, 'approvalLevel', task.approvalLevel) // 审批类别
				// 审批系数
				this.$set(this.form, 'approvalCoefficient', task.approvalCoefficient) // 审批系数
				// 复杂程度
				this.$set(this.form, 'complexity', task.complexity) // 复杂程度
				// 复杂系数
				this.$set(this.form, 'complexCoefficient', task.complexCoefficient) // 复杂系数
			} else {
				// 行业类别
				this.$set(this.form, 'industryCategory', '') // 行业类别
				// 行业系数
				this.$set(this.form, 'industryCoefficient', '') // 行业系数
				// 审批类别(环评)
				this.$set(this.form, 'approvalLevel', '') // 审批类别
				// 审批系数
				this.$set(this.form, 'approvalCoefficient', '') // 审批系数
				// 复杂程度
				this.$set(this.form, 'complexity', '') // 复杂程度
				// 复杂系数
				this.$set(this.form, 'complexCoefficient', '') // 复杂系数
			}
			
      // 流程中和从列表页点击编辑进来的不允许修改是否隐藏字段 只允许选择任务弹框修改
      if (!isEdit) {
        // 只要有这些字段 则不隐藏 没有则隐藏
        if (
          !!this.form.industryCategory ||
          !!this.form.industryCoefficient ||
          !!this.form.approvalLevel ||
          !!this.form.approvalCoefficient ||
          !!this.form.complexity ||
          !!this.form.complexCoefficient
        ) {
          this.form.hideFlag = '1'
          this.hideFlag = '1'
        } else {
          this.form.hideFlag = '0'
          this.hideFlag = '0'
        }
      }
    },
    // 选择关联任务
    // handleTaskIdChange({ data: task }) {
    handleTaskIdChange(task) {
      if (task) {
        // 当前projectId
        this.projectIdBack = this.form.projectId
        // 业务名称 categoryName
        this.$set(this.form, 'categoryName', task.categoryName) // 业务分类
				this.$set(this.form, 'taskType', task.taskType) // 任务类型
        // 项目负责人
        this.$set(this.form, 'projectLeading', task.projectLeading) // 项目负责人
        // 生产团队
        this.$set(this.form, 'productTeam', task.productTeam) // 生产团队
        // 实施部门
        this.$set(this.form, 'executeDepart', task.executeDepart) // 实施部门
        // 带出 带不出隐藏
        this.fillOrHide(task, false)
      } else {
        // 清空
        this.resetTaskFields()
        this.projectIdBack = null
      }
    },
    // 清空数据
    restProjectFields() {
      // 项目编号（档案编号）
      this.$set(this.form, 'finalNo', '')
      // 签订单位
      this.$set(this.form, 'signUnit', '')
      // 项目地址
      this.$set(this.form, 'areaCode', '')
      this.$set(this.form, 'projectAddress', '')
    },
    resetTaskFields() {
      // 业务名称 categoryName
      this.$set(this.form, 'categoryName', '') // 业务分类
      // 项目负责人
      this.$set(this.form, 'projectLeading', '') // 项目负责人
      // 生产团队
      this.$set(this.form, 'productTeam', '') // 生产团队
      // 实施部门
      this.$set(this.form, 'executeDepart', '') // 实施部门
      // 行业类别
      this.$set(this.form, 'industryCategory', '') // 行业类别
      // 行业系数
      this.$set(this.form, 'industryCoefficient', '') // 行业系数
      // 审批类别(环评)
      this.$set(this.form, 'approvalLevel', '') // 审批类别
      // 审批系数
      this.$set(this.form, 'approvalCoefficient', '') // 审批系数
      // 复杂程度
      this.$set(this.form, 'complexity', '') // 复杂程度
      // 复杂系数
      this.$set(this.form, 'complexCoefficient', '') // 复杂系数
    },
    // 选择项目名称
    handleProjectIdChange(data) {
      let project = data
      if (data && project) {
        // 项目编号（档案编号）
        this.$set(this.form, 'finalNo', project.finalNo)
        // 项目名称
        this.$set(this.form, 'projectName', project.projectName)
        this.$set(this.form, 'operateTeamId', project.teamName)
        // 签订单位
        this.$set(this.form, 'signUnit', project.signUnit)
        // 项目地址
        this.$set(this.form, 'areaCode', project.areaCode)
        this.$set(this.form, 'projectAddress', project.projectAddress)
        // 如果当前项目和任务关联的项目不一样则清空任务
        if (this.projectIdBack !== project.id) {
          this.projectIdBack = null
          this.$set(this.form, 'taskId', '')
          // 清空任务相关字段
          this.resetTaskFields()
        }
      } else {
        // 清空所有
        this.restProjectFields()
        // 清空任务相关字段
        this.resetTaskFields()
        this.projectIdBack = null
        this.$set(this.form, 'taskId', '')
      }
    },
    // ...mapState(['userInfo']),
    // 查询预立项申请详情
    loadData(id) {
      info({ id }).then(async (res) => {
        if (res.success) {
          this.form = { ...res.result }
          this.$nextTick(()=>{
        //     firstAuditEngineers:{
        //   deptId:'',
        //   empId:'',
        //   expectedAuditFee:'0',
        //   actualAuditFee:'0',
        //   remark:'',
        //   teamId:'',
        //   deductionRatio:'0',
        //   attachment:'',
        //   remark:'',
        //   userType:'one_engineer'
        // },
            this.$refs.firstInstanceEngineerList.firstAuditEngineers.empId = this.form.firstAuditEngineers[0].empId
            this.$refs.firstInstanceEngineerList.firstAuditEngineers.teamId = this.form.firstAuditEngineers[0].teamId
            this.$refs.firstInstanceEngineerList.firstAuditEngineers.expectedAuditFee = this.form.firstAuditEngineers[0].expectedAuditFee
            this.$refs.firstInstanceEngineerList.firstAuditEngineers.actualAuditFee = this.form.firstAuditEngineers[0].actualAuditFee
            this.$refs.firstInstanceEngineerList.firstAuditEngineers.remark = this.form.firstAuditEngineers[0].remark
            this.$refs.firstInstanceEngineerList.firstAuditEngineers.deductionRatio = this.form.firstAuditEngineers[0].deductionRatio
            this.$refs.firstInstanceEngineerList.firstAuditEngineers.attachment = this.form.firstAuditEngineers[0].attachment
          })
          console.log(this.form,'this.form-----------');
          
          this.hideFlag = res.result.hideFlag
        } else {
          this.$refs.uToast.show({
            message: res.message,
            type: 'error',
          })
        }
      })
    },
    // 约束数字输入框
    // onBlur(item, text) {
    //   if (item == undefined || item == null) {
    //     return false
    //   }
    //   var num = Number(item)
    //   if (num <= 0) {
    //     num = 0
    //   }
    //   if (num >= 99999) {
    //     num = 99999
    //   }
    //   this.form[text] = num.toFixed(1)
    // },
    // 获取单据编号
    async initBillNo() {
      const res = await getBillNo({
          prefix:'BGSHD',
          subSystemCode:'05'
        })
      this.form.billNo = res.result
    },

    // 初始化新增需要的数据
    initForm() {
      this.form.handlerId = this.userInfo.empId //当前登录人
      this.form.handlerDeptId = this.userInfo.deptId //当前登录人部门
      this.form.createTime = moment().format('YYYY-MM-DD HH:mm:ss')
    },
    validateForm() {
       this.$refs.form.validate()
       return this.$refs.firstInstanceEngineerList.validateForm()
    },
    async initDictConfig() {
      initDictOptions('erp_omc_project,project_name,id').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'projectId', res.result)
        }
      })
    },
    getCreateTime() {
      let createTime = this.form.createTime
      let date = createTime.substring(0, 10)
      return date.substring(0, 4) + '年' + date.substring(5, 7) + '月' + date.substring(8, 10) + '日'
    },
    setBpmBizTitle() {
      const that = this
      let projectName = filterMultiDictText(that.dictOptions['projectId'], that.form.projectId + '')
      that.form.bpmBizTitle = (projectName ? projectName + ' - ':'') + this.userInfo?.employee?.name + '-' + that.getCreateTime() + '-' + that.form.billNo
    },
    async onSubmit() {
      await this.validateForm()

      if(this.form.taskType === '1' && !this.form.reportType) return this.$refs.uToast.warning('请填写报告类型')
     
      // 一审工程师
    const firstAuditEngineers =  this.$refs.firstInstanceEngineerList.firstAuditEngineers
    console.log(firstAuditEngineers,'firstAuditEngineers');
      // 二审主持工程师
    const secondAuditChairmanEngineers =  this.$refs.SecondInstancePresidingEngineerForm.firstAuditEngineers
    console.log(firstAuditEngineers,'firstAuditEngineers');
    
      // return
      this.isSubmit = true
      this.setBpmBizTitle()
      try {
        this.loading = true
        var url = ''
        if (this.id) {
          url = edit
        } else {
          url = add
        }
        const response = await url({
          ...this.form,
          firstAuditEngineers:[firstAuditEngineers]
          // details: this.formData,
        })
        if (response.success) {
          var that = this
          this.isSubmit = true
          // 获取流程列表
          if (this.form.id) {
            this.getProcessList(this.form.id)
          } else {
            // 判断添加的时候是否有返回id值
            if (response.result) {
              this.getProcessList(response.result)
            }
          }
          this.$refs.uToast.show({
            message: response.message,
            type: 'default',
            complete() {
              // that.isSubmit = false
            },
          })
        }
      } finally {
        this.loading = false
      }
    },
    // 获取流程列表
    getProcessList(id) {
			http.get('/api/erp/omc/project/erpOmcProjectTask/checkTaskChangeById', { id: this.form.taskId }).then(res => {
				if (res.success) {
					this.$refs.processConfig.showPopup = true
					this.$refs.processConfig.formUrl = this.formUrl
					this.$refs.processConfig.formUrlMobile = this.formUrlMobile
					this.$refs.processConfig.flowCode = this.flowCode
					this.$refs.processConfig.startProcess = this.urlStartProcess
					this.$refs.processConfig.edit(id, '', this.beanName)
				} else {
					this.$refs.uToast.show({
						message: res.message,
						complete () {
							if (getCurrentPages().length > 1) {
								uni.navigateBack()
							} else {
								uni.reLaunch({
									url: '/pages/home/home'
								})
							}
							
						}
					})
				}
			})
    },
    async onDraft() {
      // await this.validateForm()
      const firstAuditEngineers =  this.$refs.firstInstanceEngineerList.firstAuditEngineers
      this.isSubmit = true
      this.setBpmBizTitle()
      try {
        this.loading = true
        var url = ''
        if (this.id) {
          url = edit
        } else {
          url = add
        }
        const response = await url({
          ...this.form,
          firstAuditEngineers:[firstAuditEngineers]
          // details: this.formData,
        })
        if (response.success) {
          this.isSubmit = true
          this.$refs.uToast.show({
            message: response.message,
            type: 'default',
            complete() {
              this.isSubmit = false
              if (getCurrentPages().length > 1) {
                uni.navigateBack()
              } else {
                uni.reLaunch({
                  url: '/pages/home/home',
                })
              }
            },
          })
        }
      } finally {
        this.loading = false
      }
    },
  }
}
</script>

<style lang="scss" scoped>
@import url('@/assets/inputStyle.scss');
.trip-form-data {
  ::v-deep {
    .u-form-item__body {
      padding-top: 2px;
      padding-bottom: 2px;
    }
  }
}
.checkbox-item {
  display: flex;
  align-items: center;
}
</style>
